//
//  NYGoodAnalysisCell.m
//  NiuWaJiaoYu
//
//  Created by MinLison on 2018/1/5.
//  Copyright © 2018年 niuwaketang. All rights reserved.
//

#import "NYGoodAnalysisCell.h"
@interface NYGoodAnalysisCell ()
@property(nonatomic, strong) TTTAttributedLabel *titleLabel;
@property(nonatomic, strong) DTAttributedTextContentView *desAttrView;
@property(nonatomic, strong) NYHtmlHelper *htmlHelper;
@property(nonatomic, strong) UIView *bottomContentView;
@end
@implementation NYGoodAnalysisCell
- (BOOL)shouldUpdateCellWithObject:(NICellObject *)object atIndexPath:(NSIndexPath *)indexPath
{
        self.indexPath = indexPath;
        self.subjectModel = (NYSubjectModel *)object.userInfo;
        return YES;
}

- (void)setSubjectModel:(NYSubjectModel *)subjectModel
{
        _subjectModel = subjectModel;
        [self updateContent];
}
- (void)updateContent
{
        NSString *resString = [self.htmlHelper getImgSizeAndReplaceHtmlString:self.subjectModel.explain_ex];
        self.desAttrView.attributedString = [self.htmlHelper attributedStringForHtmlString:resString maxImageSize:CGSizeMake(__WGWidth(self.bottomContentView.width), CGFLOAT_MAX)];
        CGFloat suggestHeight = [self.desAttrView  suggestedFrameSizeToFitEntireStringConstraintedToWidth:__MAIN_SCREEN_WIDTH__ - __WGWidth(32)].height;
        [self.desAttrView mas_remakeConstraints:^(MASConstraintMaker *make) {
                make.top.left.right.bottom.equalTo(self.bottomContentView);
                make.height.mas_equalTo(suggestHeight);
        }];
}
- (void)setupView
{
        [super setupView];
        
        UIView *contentView = [[UIView alloc] init];
        [self.contentView addSubview:contentView];
        self.bottomContentView = contentView;
        [contentView addSubview:self.titleLabel];
        [contentView addSubview:self.desAttrView];
        
        [contentView mas_remakeConstraints:^(MASConstraintMaker *make) {
                make.top.equalTo(self.contentView).mas_offset(__WGHeight(15));
                make.left.equalTo(self.contentView).mas_offset(__WGHeight(16));
                make.bottom.equalTo(self.contentView).mas_offset(-__WGHeight(16)).priorityLow();
                make.right.equalTo(self.contentView).mas_offset(-__WGHeight(16));
        }];
        
        [self.titleLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
                make.top.left.right.equalTo(contentView);
        }];
        [self.desAttrView mas_remakeConstraints:^(MASConstraintMaker *make) {
                make.top.equalTo(self.titleLabel.mas_bottom).offset(__WGHeight(16));
                make.left.right.bottom.equalTo(contentView);
        }];
}

- (TTTAttributedLabel *)titleLabel
{
        if (_titleLabel == nil) {
                _titleLabel = [[TTTAttributedLabel alloc] initWithFrame:CGRectZero];
                _titleLabel.font = WGSystem14Font;
                _titleLabel.textColor = UIColorHex(0xFA8D00);
                _titleLabel.text = @"解析：";
        }
        return _titleLabel;
}
- (DTAttributedTextContentView *)desAttrView
{
        if (_desAttrView == nil) {
                _desAttrView = [self.htmlHelper createAttributedContentView];
        }
        return _desAttrView;
}
- (NYHtmlHelper *)htmlHelper
{
        if (_htmlHelper == nil) {
                _htmlHelper = [[NYHtmlHelper alloc] init];
        }
        return _htmlHelper;
}
@end
